<style scoped>
.item{
    width:250px;
}
.item span{
    width: 100px;
}
</style>
<template>
    <div class="lessonEvaluate">
        <h2 class="text-center line-height-36">{{step===1?'所有题目已回答完毕':'感谢您的评分 老师会和你一起加油'}}</h2>
        <p class="text-center my-3">{{step===1?'老师备课不易，请为老师的教学质量打个分吧！':'请为您自己的课堂表现评个分吧！'}}</p>
        <div class="list">
            <div class="item my-1 mx-auto line-height-36 mt-1" v-for="(val,key,index) in rate[step-1]" :key="key" >
                <div v-if="is_last?true:index<3 || index>5" class="d-flex">
                    <span class="mr-1">{{key}}</span>
                    <Rate style="width:180px" allow-half v-model="rate[step-1][key]"/>
                </div>
            </div>
        </div>
        <Input v-model="remark" class="my-1 mx-auto d-block" style="width:400px" type="textarea" :rows="6" placeholder="请输入评价内容" />
        <Button type="primary" size="large" class="mx-auto mt-3 d-block" @click="submit">提交</Button>
    </div>
</template>
<script>
    import { submit_teacher_evaluation,submit_self_evaluation } from "@/common/sapi";
    export default {
        props:['step','is_last','lid'],
        data(){
            return{
                remark:'',
                rate:[
                    {'教学内容':0,'教学水平':0,'教学态度':0,'授课课件':0,'授课讲解':0,'授课氛围':0,'整体评价':0},
                    {'注意力':0,'学习兴趣':0,'学习难度':0,'知识增长程度':0,'能力增长程度':0,'学习态度':0,'整体评价':0}
                ]
            }
        },
       
        methods:{
            submit(){
                if( Object.values(this.rate[this.step-1]).some((el,index)=>this.is_last?!el:( index<3 || index>5 ) && !el) ){
                    this.$Notice.warning({
                        title: '提示失败',
                        desc:'请选择评价星'
                    });
                    return 
                }
                if(!this.remark && Object.values(this.rate[this.step-1]).some((el,index)=>this.is_last?el<3:( index<3 || index>5 ) && el<3)){
                    this.$Notice.warning({
                        title: '提示失败',
                        desc:'请输入评价内容'
                    });
                    return 
                }
                const func=[submit_teacher_evaluation,submit_self_evaluation][this.step-1]
                func({
                    lid:this.lid,
                    content:JSON.stringify(this.rate[this.step-1]),
                    remark:this.remark
                })
                .then(res=>{
                    if(res){
                        this.remark=''
                        if(res.data.gold){
                            this.$emit('set_gold',res.data.gold)
                        }
                        this.$emit('addStep')
                    }
                })
            }
        },
    }
</script>